package com.flea.web.controller;

import com.flea.model.ProductDoc;
import com.flea.repository.es.ProductDocRepository;
import com.flea.repository.jdbc.ProductRepository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
public class TempController {
    @Resource
    private ProductDocRepository productDocRepository;

    @Resource
    private ProductRepository productRepository;

    @GetMapping("/temp/toEs")
    public String streamHistoryDataToEs() {

        List<ProductDoc> productDocList = new ArrayList<>();
        productRepository.findAll().forEach(p -> {
            productDocList.add(p.toDoc());

        });

        System.out.println("========query->save " + productDocList.size() + "==========");

        productDocRepository.saveAll(productDocList);

        return "Success: " + productDocList.size();
    }
}
